﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.IO.Ports;
using System.Text;
using Exhibition.Service;
namespace Exhibition.Manage
{
    public partial class FileList : BaseAdminPage
    {
        public class FileInfo{
            public string FileName{get;set;}
            public string CreateTime{get;set;}
            public string FileType { get; set; }
            public string FileSize { get; set; }
            public string FilePath { get; set; }
        }
          public class IODirectory{
            public string FileName{get;set;}
            public string CreateTime{get;set;}
            public string FileType { get; set; }
            public string FileSize { get; set; }
            public string FilePath { get; set; }
        }
        public List<FileInfo> files { get; set; }
        public List<IODirectory> directorys { get; set; }
         System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort();
         Byte[] data = new byte[90000];
            //声明已读了多少数据
            int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            var filepath = "E:\\ZHANHui";
          //  string[] directorys = Directory.GetDirectories(filepath);
            LoadFiles(filepath);
           
            //声明一个字节数组来存放从扫码枪中读出的数据
           
            //设置扫码枪使用的串口名称
            port.PortName = "COM4";
            //打开此串口
            port.Open();
            //声明扫码枪的每次触发会执行函数xlh
            port.DataReceived += new SerialDataReceivedEventHandler(xlh);


        }

          public void xlh(object sender, SerialDataReceivedEventArgs e)
        {
            //将扫码枪中的数据显示出来
           Response.Write(getData());
        }

        public String getData()
        {
            //取出扫码枪中的数据总数
            int length = port.BytesToRead;
            for (int i = 0; i < length;i++ )
            {
                //每次从扫码枪中读出一个字节的数据
                data[count] = (byte)port.ReadByte();
                count++;
            }
            //声明字节转字符类
            UTF8Encoding enc = new UTF8Encoding();
            //将扫码枪中的字节数组转换成字符串
            String returnDate = enc.GetString(data);
            //返回字符串
            return returnDate;
        }
     



        public void LoadFiles(string filePath){
            foreach (var f in Directory.GetDirectories(filePath)) {
                IODirectory ido = new IODirectory();
                ido.FileName = f.ToString();
                directorys.Add(ido);
              
                //foreach(var file in )
               
            }
            string[] fls = Directory.GetFiles(filePath);
            foreach (string file in fls)
            {
                FileInfo info = new FileInfo();
                info.FileName = file.ToString();
                files.Add(info);
                //if (info.Name == fileName)
                //{
                //    fileFullName = info.FullName;
                //}

            }  

        }

    }
}